<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';

$pd=new pdo_mysql();
$filter=new Filter();
session_start();

if(empty($_SESSION['uid'])){
    $tips=array(
		'tips'=>'请登录后再进行操作',
		'url'=>'index.php'
	);
	$tips=urlencode(serialize($tips));
	header('Location:/tips.php?gets='.$tips);
	exit;
}

$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
	//if(!empty($_POST['period']))$period=implode(',', array_keys($_POST['period']));
	$period="";
	if(!empty($_POST['period'])){
		$period=implode(',', array_keys($_POST['period'])); 
	}
	$aid="0";
	if(!empty($_POST['areaid'])){
		$aid=$_POST['areaid'];
	}
	
    $now        = date('Y-m-d H:i:s');
    $id         = empty($_POST['id'])?0:Filter::filter_number($_POST['id']);
	$sch_name   = Filter::safe_string($_POST['sch_name']);
	$short_name = Filter::safe_string($_POST['short_name']);
	$sch_urls   = Filter::safe_string($_POST['sch_urls']);
	$sch_code   = Filter::safe_string($_POST['sch_code']);
	$sch_logo   = Filter::safe_string($_POST['sch_logo']);
	$period     = Filter::safe_string($period);
	$mechanism  = empty($_POST['mechanism'])?0:Filter::filter_number($_POST['mechanism']);
	$mtype      = empty($_POST['mtype'])?0:Filter::filter_number($_POST['mtype']);
	$areaid     = Filter::filter_number($aid);
	$addr       = Filter::safe_string($_POST['addr']);
	$linkman    = Filter::safe_string($_POST['linkman']);
	$tel        = Filter::safe_string($_POST['tel']);
	$fax        = Filter::safe_string($_POST['fax']);
	$emails     = Filter::safe_string($_POST['email']);
	$abst       = Filter::safe_string($_POST['abst']);
	$flag       = empty($_POST['flag'])?0:Filter::filter_number($_POST['flag']);
	$superior   = empty($_POST['superior'])?0:Filter::filter_number($_POST['superior']);

	$in_data=array(
		'sch_name'   =>$sch_name,
		'short_name' =>$short_name,
		'sch_urls'   =>$sch_urls,
		'sch_code'   =>$sch_code,
		'sch_logo'   =>$sch_logo,
		'period'     =>$period,
		'mechanism'  =>$mechanism,
		'mtype'      =>$mtype,
		'areaid'     =>$areaid,
		'addr'       =>$addr,
		'linkman'    =>$linkman,
		'tel'        =>$tel,
		'linkman'    =>$linkman,
		'fax'        =>$fax,
		'emails'     =>$emails,
		'abst'       =>$abst,
		'flag'       =>$flag,
		'superior'       =>$superior
	);

	$result=0;
	$tps='';
	if($id==0){
		$result=$pd->insert(array('data'=>$in_data,'table'=>'sys_school'));
		$tps='添加成功';
	}else{
		$result=$pd->update(array('data'=>$in_data,'table'=>'sys_school','where'=>"id=".$id));
		$tps='修改成功';
	}
	if(empty($result)){
		echo "ok";exit;
	}else{
		echo "ok";exit;
	}
}else{
	echo "不允许的表单提交方式，请按正常流程提交表单。";exit;
}
?>